package com.mxpio.erp.common.equipment.service;

import com.mxpio.erp.common.equipment.entity.EquipmentRepair;
import com.mxpio.erp.common.equipment.entity.EquipmentRepairEvaluateDetail;
import com.mxpio.erp.common.equipment.entity.EquipmentRepairPickupLine;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import com.mxpioframework.common.exception.MBootException;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.BaseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Description: 设备维修
 * @Author: jeecg-boot
 * @Date:   2021-09-23
 * @Version: V1.0
 */
public interface EquipmentRepairService extends BaseService<EquipmentRepair> {

	/**
	 * 删除一对多
	 */
	public void delMain(String bizNo);

	/**
	 * 批量删除一对多
	 */
	public void delBatchMain(Collection<? extends Serializable> bizNoList);


	/**
	 * 添加
	 * @param equipmentRepair
	 */
    void saveRepair(EquipmentRepair equipmentRepair);

	/**
	 * 修改
	 * @param equipmentRepair
	 */
	void updateRepairById(EquipmentRepair equipmentRepair);

	/**
	 * 派工
	 * @param equipmentRepair
	 */
	void sendRepairById(EquipmentRepair equipmentRepair);

	/**
	 * 改派
	 * @param reason
	 * @param userId
	 * @param id
	 */
	void reSendRepairById(String reason, String userId, String id);

	/**
	 * 根据ID开始维修
	 * @param
	 */
	void start(EquipmentRepair equipmentRepair);

	@Transactional
	Result<?> veto(EquipmentRepair equipmentRepair);

	/**
	 * 根据ID结束维修
	 * @param
	 */
	void finish(EquipmentRepair equipmentRepair);

	/**
	 * 暂停
	 * @param reason
	 * @param id
	 */
	void stopRepairById(String reason, String id);

	/**
	 * 暂停结束
	 * @param id
	 */
	void endStop(String id);

	/**
	 * 验收完成
	 * @param id
	 */
	void check(String id, Integer evaluateStar,HttpServletRequest request) throws MBootException;

	/**
	 * 验收驳回
	 * @param id
	 */
	void reject(String id, String reason) throws MBootException ;

	/**
	 * 抢单
	 * @param equipmentRepair
	 */
	void grabRepairById(EquipmentRepair equipmentRepair);

	/**
	 * 签核驳回
	 * @param repairId
	 */
	void signOffBack(String repairId, String reason);

	/**
	 * 同步离线数据
	 * @param equipmentRepair
	 * @param history
	 * @return
	 */
	public void executeOffLineData(EquipmentRepair equipmentRepair, List<Map> history);

	/**
	 * 查询列表
	 * @param flag
	 * @param applyStart
	 * @param applyEnd
	 * @param planRepairStart
	 * @param planRepairEnd
	 * @param failureTime
	 * @param req
	 * @return
	 */
	Page<EquipmentRepair> getTpmRepairIPage(Criteria criteria, Pageable page, String flag,  String applyStart,  String applyEnd,  String planRepairStart,  String planRepairEnd,  String failureTime, HttpServletRequest req);

	/**
	 * 查询维修中的列表
	 * @return
	 */
    List<EquipmentRepair> queryRepairingList();

    EquipmentRepair getByOrderCode(String orderCode);

	Result<?> evaluate(EquipmentRepair equipmentRepair);

	Result<?> statement(EquipmentRepair equipmentRepair);

	Result<?> cancle(EquipmentRepair equipmentRepair);

    Result<List<EquipmentRepair>> getNowadaysListByAreaid(String areaid);

	Result<List<Map<String, Object>>> getSevendaysCntGroupbyFaultType(String areaid);

	Result<List<Map<String, Object>>> getSevendaysCntGroupbySecondArea(String areaid);

    Result<List<EquipmentRepairPickupLine>> executePickUp(EquipmentRepair order, List<OrderExcuteLineVo> lines);

    Result<Object> executeReturn(EquipmentRepair order, List<OrderExcuteLineVo> lines);

	Result<?> submit(EquipmentRepair equipmentRepair);

	Result<?> change(EquipmentRepair equipmentRepair);

	Result<?> check(EquipmentRepair equipmentRepair);

	Result<List<EquipmentRepairEvaluateDetail>> saveDetailsAndEvaluta(List<EquipmentRepairEvaluateDetail> details);

	Result<?> shut(EquipmentRepair equipmentRepair);

//	/**
//	 * 计算超时时间
//	 */
//
//	void goBeyondMinutes(Page<EquipmentRepair> pageResult );

	/**
	 * 获取故障设备数量,进行去重
	 * @param criteria
	 * @param page
	 * @return
	 */
	Page<EquipmentRepair> getTheNumberOfFaultyDevices(Criteria criteria, Pageable page);

	/**
	 * 当前登录用户协助的工单信息
	 * @param criteria
	 * @param page
	 * @return
	 */
	Page<EquipmentRepair> userAssistedTickets(Criteria criteria, Pageable page);

	List<Map<String, Object>> listTOP(Criteria criteria);

	void getTheTotalDowntime ();

    Result<?> confirm(EquipmentRepair equipmentRepair);

	/**
	 * 判断评价是否通过
	 * @param equipmentRepair
	 * @return
	 */
    EquipmentRepair isEvaluate(EquipmentRepair equipmentRepair);

	void updateAdminRepairById(EquipmentRepair equipmentRepair);

}
